package com.lepu.app.fun.my;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.app.utils.LoginUtil;
import com.core.lib.application.BaseFragmentActivity;
import com.eyzhs.app.R;
import com.lepu.app.fun.grow.GrowMessageActivity;
import com.lepu.app.fun.my.bean.BeanMessage;
import com.lepu.app.fun.my.bean.BeanMessageCount;
import com.lepu.app.widget.CustomTopBarNew;
import com.lepu.app.widget.CustomTopBarNew.OnTopbarNewLeftLayoutListener;

public class MessageAllActivity extends BaseFragmentActivity implements
		OnTopbarNewLeftLayoutListener {
	private TextView motherText;
	private TextView phoneText;
	private TextView writerText;
	private TextView friendText;
	private TextView systemText;
	
	private BeanMessageCount beanMessage = null;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.all_message_activity);

		init();
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
	}

	/**
	 * 添加页面动画，需要重写这个方法，
	 */
	@Override
	public void onBackPressed() {
		finish(true);
	}
	
	@Override
	public void onTopbarLeftLayoutSelected() {
		finish(true);
	}


	/**
	 * 初始化方法
	 */
	private void init() {
		// topbar
		CustomTopBarNew topbar = (CustomTopBarNew) findViewById(R.id.topbar);
		topbar.setTopbarTitle("我的消息");
		topbar.setonTopbarNewLeftLayoutListener(this);
		
		RelativeLayout motherLayout = (RelativeLayout) findViewById(R.id.motherLayout);
		RelativeLayout phoneLayout = (RelativeLayout) findViewById(R.id.phoneLayout);
		RelativeLayout writerLayout = (RelativeLayout) findViewById(R.id.writerLayout);
		RelativeLayout friendLayout = (RelativeLayout) findViewById(R.id.friendLayout);
		RelativeLayout systemLayout = (RelativeLayout) findViewById(R.id.systemLayout);
		
		motherText = (TextView) findViewById(R.id.motherText);
		phoneText = (TextView) findViewById(R.id.phoneText);
		writerText = (TextView) findViewById(R.id.writerText);
		friendText = (TextView) findViewById(R.id.friendText);
		systemText = (TextView) findViewById(R.id.systemText);
		
		motherLayout.setOnClickListener(onClick);
		phoneLayout.setOnClickListener(onClick);
		writerLayout.setOnClickListener(onClick);
		friendLayout.setOnClickListener(onClick);
		systemLayout.setOnClickListener(onClick);
		
		beanMessage = (BeanMessageCount) getIntent().getSerializableExtra("beanMsg");
		
		if(beanMessage != null){
			showPoint(beanMessage);
		}
		
	}
	
	//显示红点及数量
	public void showPoint(BeanMessageCount beanMsg){
		
		if(beanMsg.motherCount != 0){
			motherText.setVisibility(View.VISIBLE);
			motherText.setText(String.valueOf(beanMsg.motherCount));
		}
		
		if(beanMsg.phoneCount != 0){
			phoneText.setVisibility(View.VISIBLE);
			phoneText.setText(String.valueOf(beanMsg.phoneCount));
		}
		
		if(beanMsg.writerCount != 0){
			writerText.setVisibility(View.VISIBLE);
			writerText.setText(String.valueOf(beanMsg.writerCount));
		}
		
		if(beanMsg.friendCount != 0){
			friendText.setVisibility(View.VISIBLE);
			friendText.setText(String.valueOf(beanMsg.friendCount));
		}
		
		if(beanMsg.systemCount != 0){
			systemText.setVisibility(View.VISIBLE);
			systemText.setText(String.valueOf(beanMsg.systemCount));
		}
		
	}
	
	View.OnClickListener onClick = new View.OnClickListener() {
		
		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.motherLayout:
				boolean flag1 = LoginUtil.jumpLogin(MessageAllActivity.this);
				if(flag1){
					return;
				}
				Intent intent1 = new Intent(MessageAllActivity.this,GrowMessageActivity.class);
				intent1.putExtra("type", 2);
				startActivity(intent1,true);
				
				motherText.setVisibility(View.GONE);
				break;
			case R.id.phoneLayout:
				boolean flag2 = LoginUtil.jumpLogin(MessageAllActivity.this);
				if(flag2){
					return;
				}
				Intent intent2 = new Intent(MessageAllActivity.this,GrowMessageActivity.class);
				intent2.putExtra("type", 1);
				startActivity(intent2,true);
				
				phoneText.setVisibility(View.GONE);
				break;
			case R.id.writerLayout:
				boolean flag3 = LoginUtil.jumpLogin(MessageAllActivity.this);
				if(flag3){
					return;
				}
				Intent intent3 = new Intent(MessageAllActivity.this,MessageWriterActivity.class);
				intent3.putExtra("type", 3);
				startActivity(intent3,true);
				
				writerText.setVisibility(View.GONE);
				break;
			case R.id.friendLayout:
				boolean flag4 = LoginUtil.jumpLogin(MessageAllActivity.this);
				if(flag4){
					return;
				}
				Intent intent4 = new Intent(MessageAllActivity.this,MessageFriendActivity.class);
				intent4.putExtra("type", 5);
				startActivity(intent4,true);
				
				friendText.setVisibility(View.GONE);
				break;
			case R.id.systemLayout:
				Intent intent5 = new Intent(MessageAllActivity.this,MyMessageActivity.class);
				intent5.putExtra("type", 4);
				startActivity(intent5,true);
				
				systemText.setVisibility(View.GONE);
				break;
			default:
				break;
			}
		}
	};
	
}
